<?php

namespace controllers;


class _SkyCMS_Controller extends \libs\controller{
    
    
    public function __construct($options,$request) 
    {    
        parent::__construct($options);
        
        $logReq = true;
        
        if($request == '/login' || $request == '/login/result' || preg_match('/reset\/[a-zA-Z0-9,\.\&-=()_\/\{()\}]*/',$request))
        {
            $logReq = false;
        }
        
        if(empty($this->options))
        {
            $this->options = $options;
        }
        
        $this->_logReq = $logReq;
        
        $this->loginCheck('login');
        
    }

    public function loginCheck($direction)
    {
        if($this->_logReq == true && $_SESSION['loggedIn'] != true) 
        {
            header("Location: ".URL. '_SkyCMS/'. $direction);
        }
    }
    
    public function uprawnieniaCheck($dzial,$direction = '')
    {
        if(!in_array($_SESSION['login'], array('Master','Admin','admin')))
        {
            if(!in_array($dzial,$_SESSION['uprawnienia']))
            {   
                header("Location: ".URL. '_SkyCMS/'. $direction);
            }
        }
        
    }
    
}

?>
